-
Notifications
You must be signed in to change notification settings - Fork 764
switch to GA4 event structure #5914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
06f7022
to
60a9191
Compare
69b0095
to
629bf4f
Compare
6f81cfb
to
4630dcc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two questions but nothing to stop an approval from me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work! I added a few comments some of which need to be addressed before merging but I am not blocking the review.
Regarding merging itself, this PR needs a bit of restructuring around the commits. I would advice to bundle commits contextually. Eg remove unused code one commit, functionality needed to get GA4 to work another one etc etc. Maybe a couple could be dropped (eg adding/removing debugging symbols)?
We need to be able to revert a single commit to restore a previous state.
Great work 🚀
kitsune/wiki/jinja2/wiki/base.html
Outdated
@@ -5,3 +5,6 @@ | |||
{% if product %} | |||
{% set search_params = {'product': product.slug} %} | |||
{% endif %} | |||
{% if not ga_content_group %} | |||
{% set ga_content_group = "kb-other" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to set this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of this as a default value for ga_content_group
for any future wiki page that didn't set it, so at least the new page is placed within a KB bucket rather than being placed within the (unset)
content group. However, I'm fine with removing it too.
@@ -2,3 +2,6 @@ | |||
{% if not scripts %} | |||
{% set scripts = ('questions',) %} | |||
{% endif %} | |||
{% if not ga_content_group %} | |||
{% set ga_content_group = "support-forums-other" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the other comment on a base
template. Is this needed? Or rephrasing, this will be always set with every page that extends it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary, but I was thinking of this as a default value.
bee994a
to
d8930a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r+wc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r+wc
mozilla/sumo#1646
This PR switches our GA events from their current GA3 event structure (
category
,action
,label
) to the new GA4 structure of an eventname
with zero or more eventparameters
.It assumes that its complementary PR -- that sets the proper GA4 value for
GTM_CONTAINER_ID
-- will be merged prior to deploying this PR.Notes
I will remove all of the
console.log
calls and thedebug_mode
configuration before merging.This PR does not address the changes needed to convert
kitsune/sumo/googleanalytics.py
to use the Analytics Data API for GA4. That work is tracked with [GA4] Convert current GA API queries to use the Analytics Data API for GA4 sumo#1705.It's best to start reviewing by looking at
analytics.js
andgtm-snippet.js
, as together they implement the core functionality.In GA4, there are many events which are sent automatically. Some of the most important ones are:
page_view
-- Sent when the page loads.click
-- Sent when user clicks on links to external domains. It is not sent for clicks on links to internal targets.form_submit
-- Sent when a form is submitted.All custom event names have been standardized on the
<noun>_<verb>
format, with the noun in snake-case if it has more than one word.There are a set of parameters that are configured to be sent with all GA4 events sent from a page, and they are:
content_group
-- This one is a key new event parameter that allows us to bucket all page views into groups, for examplekb-article
orkb-cms
orproduct-home
, and so on. Eventually, all of our pages will include acontent-group
, but currently some pages, like our dashboard pages for example, do not yet have this defined. See [GA4] Implement the GA4content_group
parameter for all pages sumo#1708.default_slug
-- This one is currently only defined for KB article pages. It provides the article'sparent.slug
if the article is a translation, and theslug
otherwise.locale
-- The locale of the page (e.g.,en-US
orde
). This is always defined and sent.products
-- All of the products related to the page, if any, where each product is represented by its slug wrapped in forward slashes, so for example/firefox/
or/mobile/
or, in the case when multiple products are involved,/firefox/mobile/ios/
. This will always be present, for example, for a product home page or a product-and-topic home page, or any other page that's associated with a product. This parameter allows us to group page views and other events into product buckets.topics
-- All of the topics related to the page, if any, where each topic is represented by its slug wrapped in forward slashes, so for example/fix-problems/
or/sync-and-save/
or, in the case when multiple topics are involved,/fix-problems/sync-and-save/
. This will always be present, for example, for a product-and-topic home page, or any other page that's clearly associated with a topic. This parameter allows us to group page views and other events into topic buckets.analytics.js
has been converted to vanilla JS and greatly simplified.Now all HTML elements that have the
data-event-name
attribute defined will have a event listener added that will make atrackEvent()
call when the element is clicked.Another big change is that we no longer delay the original
click
event for 250ms in order to make time for thetrackEvent()
call in case we're leaving the current page. That may have been needed in the past, but no longer. See this GA4 doc, specifically under the sectionEvent batching for Google Analytics 4 properties
, where you'll see the following comment:It exports a new function called
addGAEventListeners
that can be used to instrument dynamically-added DOM content, as is done for "instant" search results (seekitsune/sumo/static/sumo/js/instant_search.js
).For
link_click
events, it automatically adds thelink_url
event parameter if it hasn't been already added.There are huge changes to the GA search events, all for the better.
search
event name andsearch_term
event parameter, with the following added custom event parameters:search_product_filter
search_content_filter
All existing GA3 events have been converted to the new GA4 structure, except for three of them, which no longer made sense or were never triggered anyway:
Instant Search
, data-event-action=Exit Search
, and data-event-label=(search query URL)Ask A Question flow
, data-event-action=step 3 confirmed page
navigation
, data-event-action=main navigation
, and data-event-label=Contributor Tools
New GA4 events have been added.
While QA'ing the GA4 events in this PR, @emilghittasv discovered that the device-migration wizard never reported some GA events.
connectedCallback
method inkitsune/sumo/static/sumo/js/form-wizard-configure-step.js
for the changes that fixed the following:document_macros.html
has been cleaned up.kb_subtopic_documents
andkb_subtopic_tabs
macros were removed, since they were not used.search.js
has been cleaned-up and converted to vanilla JS.jQuery
andjQuery-UI
-based code wasn't used, so I removed it.ajaxvote.js
that triggers a jQueryvote
event, to instead dispatch a vanilla DOMvote
event. All of our code that listens for thatvote
event has been converted to vanilla JS, so there's no longer a need to trigger the jQueryvote
event. Note that this was necessary because vanilla JS event listeners are not triggered by jQuery events.wiki.metrics.js
has been converted to vanilla JS. It no longer depends onjQuery
.questions.metrics.js
has been converted to vanilla JS. It no longer depends onjQuery
.The
topic
argument of theproduct_cards()
macro withinkitsune/products/jinja2/products/includes/product_macros.html
was removed. It was never used, so always set to its default value ofNone
.Next Steps
content_group
.